<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class CommentGoods extends \app\BaseModel
{
    protected $name = "massage_service_order_comment_goods";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("top desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function commentAdd($data, $uniacid, $id)
    {
        if(!empty($data)) {
            foreach ($data as $v) {
                $insert = ["uniacid" => $uniacid, "comment_id" => $id, "star" => $v["star"], "service_id" => $v["service_id"]];
                $this->dataAdd($insert);
                $this->commentUpdate($v["service_id"]);
            }
        }
        return true;
    }
    public function commentUpdate($service_id)
    {
        $all_count = $this->where(["service_id" => $service_id])->count();
        $all_star = $this->where(["service_id" => $service_id])->sum("star");
        $now_star = 0 < $all_count ? round($all_star / $all_count, 1) : 5;
        $now_star = 5 < $now_star ? 5 : $now_star;
        $service_model = new Service();
        $service_model->dataUpdate(["id" => $service_id], ["star" => $now_star]);
        return true;
    }
}

?>